package com.msconfig.mvp.view.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.geo.msconfig.R;
import com.msconfig.event.WifiFrequencyBandDialogDismissEvent;

import org.greenrobot.eventbus.EventBus;

import static com.msconfig.mvp.view.fragment.SetupWifiFragment.WIFIBAND;

public class SetupWifiFrequencyBandDialogActivity extends Activity implements View.OnClickListener {

    private RelativeLayout rl24g;
    private RelativeLayout rl5g;
    private TextView tv24g;
    private TextView tv5g;
    private CheckBox cb24g;
    private CheckBox cb5g;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_activity_setup_wifi_frequency_band_dialog);
        rl24g=findViewById(R.id.rl_24g);
        rl5g=findViewById(R.id.rl_5g);
        tv24g=findViewById(R.id.tv_24g);
        tv5g=findViewById(R.id.tv_5g);
        cb24g=findViewById(R.id.cb_24g);
        cb5g=findViewById(R.id.cb_5g);
        rl24g.setOnClickListener(this);
        rl5g.setOnClickListener(this);
        String wifiBand=getIntent().getStringExtra(WIFIBAND);
        if(wifiBand.equals(getResources().getString(R.string.band_24g))){
            cb24g.setChecked(true);
        }else if(wifiBand.equals(getResources().getString(R.string.band_5g))){
            cb5g.setChecked(true);
        }else{
            cb24g.setChecked(true);
        }
    }

    @Override
    public void onClick(View v) {
        if(v==rl24g){
            EventBus.getDefault().post(new WifiFrequencyBandDialogDismissEvent(tv24g.getText().toString().trim()));
            finish();
        }else if(v==rl5g){
            EventBus.getDefault().post(new WifiFrequencyBandDialogDismissEvent(tv5g.getText().toString().trim()));
            finish();
        }
    }
}
